package com.example.finalassignment.common;

import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * 存放常量
 */

public class Constant {

    /**
     * 项目根路径
     */
    public static String PROJECT_URL = System.getProperty("user.dir");

    /**
     * 获取ip 获取失败就用127.0.0.1
     */
    public static String SERVER_IP = "获取失败".equals(getIp()) ? "127.0.0.1" : getIp();

    /**
     * 文件存放地址
     */
    public static String FILE_ADDRESS = PROJECT_URL + "/files";

    /**
     * 视频存放地址
     */
    public static String VIDEO_ADDRESS = PROJECT_URL + "/videos";

    /**
     * 获取本机ip
     */
    private static String getIp() {
        try {
            InetAddress localHost = InetAddress.getLocalHost();
            return localHost.getHostAddress();
        } catch (UnknownHostException e) {
            e.printStackTrace();
            return "获取失败";
        }
    }
}
